package com.xxwy.dependency.ioccontainer;

import com.xxwy.dependency.User;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

import java.util.Map;

/**
 * @author wy
 * @date 2020/4/20 14:55
 */
public class AnnotationApplicationContextDemo {

  public static void main(String[] args) {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    //当前类作为AnnotationApplicationContextDemo.class配置类
    applicationContext.register(AnnotationApplicationContextDemo.class);

    //启动应用上下文
    applicationContext.refresh();

    Map<String, User> beansOfType = applicationContext.getBeansOfType(User.class);
    beansOfType.entrySet().forEach(System.out::println);
    applicationContext.close();

  }

  @Bean
  public User user(){
    User user = new User();
    user.setId(45);
    user.setName("xx");
    return user;
  }
}
